package com.shop2cn.iapi.prodstockmgr.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonArray;
import com.shop2cn.iapi.prodstockmgr.parameter.DeleteInventoryBean;
import com.shop2cn.iapi.prodstockmgr.service.DeleteInventoryCall;
import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.ProductDetailsDto;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.Shop2cnStockCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;

/**
 * 删除库存清单Test FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_DeleteInventory {
	private static DeleteInventoryBean deleteinventoryBean;
	private static DeleteInventoryCall deleteinventoryCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("删除库存清单Test");
	}


	@Before
	public void caseUp() {
		deleteinventoryBean = new DeleteInventoryBean();
		deleteinventoryCall = new DeleteInventoryCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(deleteinventoryCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_DeleteInventory_001() {
		Logger.start(true, "把入库单取消，库存回归，成功");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchid,
					"", true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			String stockIn = Shop2cnStockCallService.stockIn(mchid, productId, 10);
			Thread.sleep(1000);
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchid, productId);
			deleteinventoryBean.setInventoryNo(Integer.parseInt(stockIn));
			deleteinventoryBean.setSellerId(mchid);
			deleteinventoryCall.setData(deleteinventoryBean);
			deleteinventoryCall.callService();
			Logger.verifyEquals("200", deleteinventoryCall.getString("code"), "验证code");
			Thread.sleep(1000);
			ProductDetailsDto selectProductDetails1 = AddAgentProductCallService.selectProductDetails(mchid, productId);
			Logger.verifyNotEquals(selectProductDetails.getCatalogList().get(0).getStock(), selectProductDetails1.getCatalogList().get(0).getStock(), "");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_DeleteInventory_002() {
		Logger.start(true, "把出库单取消，库存回归，成功");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchid,
					"", true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			String stockIn = Shop2cnStockCallService.stockOut(mchid, productId, 10);
			Thread.sleep(1000);
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchid, productId);
			deleteinventoryBean.setInventoryNo(Integer.parseInt(stockIn));
			deleteinventoryBean.setSellerId(mchid);
			deleteinventoryCall.setData(deleteinventoryBean);
			deleteinventoryCall.callService();
			Logger.verifyEquals("200", deleteinventoryCall.getString("code"), "验证code");
			Thread.sleep(1000);
			ProductDetailsDto selectProductDetails1 = AddAgentProductCallService.selectProductDetails(mchid, productId);
			Logger.verifyNotEquals(selectProductDetails.getCatalogList().get(0).getStock(), selectProductDetails1.getCatalogList().get(0).getStock(), "");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
}